package com.huike.clues.service.impl;


import com.huike.clues.domain.dto.ClueTrackRecordDto;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.core.page.TableDataInfo;
import com.huike.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * 线索跟进记录Service业务层处理
 *
 * @author wuzhiyong
 * @date 2022-04-22
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {
    @Autowired
    private TbClueTrackRecordMapper clueTrackRecordMapper;

    /**
     * 添加跟进记录
     *
     * @return
     */
    @Override
    public boolean insertClueTrackRecord(ClueTrackRecordDto clueTrackRecordDto) {
        String username = SecurityUtils.getUsername();
        clueTrackRecordDto.setCreateBy(username);
        int i = clueTrackRecordMapper.insertCluesRecord(clueTrackRecordDto);
        int j = clueTrackRecordMapper.updateClues(clueTrackRecordDto);
        return i > 0 && j > 0;

    }

    @Override
    public TableDataInfo selectCluesRecord(Long clueId) {
        List<ClueTrackRecordDto> clueTrackRecordDtos = clueTrackRecordMapper.selectCluesRecord(clueId);
        TableDataInfo tableDataInfo = new TableDataInfo();
        tableDataInfo.setTotal(clueTrackRecordDtos.size());
        tableDataInfo.setRows(clueTrackRecordDtos);
        tableDataInfo.setCode(200);
        tableDataInfo.setMsg("查询成功");
        return tableDataInfo;

    }
}
